package com.cpc.mback.controller;


import com.cpc.mback.RespEntity;
import com.cpc.mback.entity.Content;
import com.cpc.mback.service.MainService;
import com.cpc.mback.service.RecordService;
import com.cpc.mback.service.UserService;
import io.swagger.annotations.Api;
import lombok.Data;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

@RestController
@Api(value = "记录",tags="主要接口2",description ="没有description" )
@RequestMapping("/api/record")
public class RecordController {

    @Autowired
    RecordService recordService;
    @Autowired
    MainService mainService;
    @Autowired
    UserService userService;
    /*
    @PostMapping("/record")
    public ResponseEntity getInfo(@RequestBody Payload payload) {
        if (userService.checkRegistered(payload.openId)) {
            Content content = mainService.fetch(Long.valueOf(payload.id));
            recordService.createRecord(Long.valueOf(payload.openId), Long.valueOf(payload.id), payload.content, Integer.parseInt(payload.type));
            return ResponseEntity.status(200).body(RespEntity.code(200).body(content).build());
        } else {
            userService.SignUp(payload.openId);
            Content content = mainService.fetch(Long.valueOf(payload.id));
            recordService.createRecord(Long.valueOf(payload.openId), Long.valueOf(payload.id), payload.content, Integer.parseInt(payload.type));
            return ResponseEntity.status(200).body(RespEntity.code(200).body(content).build());
        }
    }*/

    /*
    @GetMapping
    public Page<Content> page(@RequestParam(defaultValue = "1") Integer page,
                              @RequestParam(defaultValue = "10") Integer size) {
        return recordService.page(PageRequest.of(page - 1, size));
    }

    @GetMapping("/standard")
    public Page<Content> getStandardContent(@RequestParam(defaultValue = "1") Integer page,
                                            @RequestParam(defaultValue = "10") Integer size) {

        Content.Type type = Content.Type.standard;
        return mainService.getMain(type,PageRequest.of(page - 1, size));
    }*/

        @Data
        private static class Payload {
            private String type;
            private String id;
            private String openId;
            private String content;
        }
}
